package com.company;

import java.io.*;

/**
 * Created by huaijie on 12/25/15.
 */
public class RenamePackage {
    private static final String PROJECT_DIRECTORY = "/Users/huaijie/AndroidStudioProjects/RecyclerView/recyclerview/src/main/java/cn/ismartv/recyclerview";

    public static void main(String[] args) {
        File file = new File(PROJECT_DIRECTORY);
        handler(file);
    }


    private static void handler(File file) {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File f : files) {
                handler(f);
            }
        } else if (file.isFile()) {
            replaceFileString(file);
        }
    }

    private static void replaceFileString(File file) {
        String oldString = "<p/>";
        String newString = "";
        StringBuffer stringBuffer = new StringBuffer();

        try {
            BufferedReader reader = new BufferedReader(new FileReader(file));
            String lineContent;
            while ((lineContent = reader.readLine()) != null) {
                lineContent = lineContent.replace(oldString, newString);
                stringBuffer.append(lineContent).append("\n");
            }
            reader.close();
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
            bufferedWriter.write(stringBuffer.toString());
            bufferedWriter.flush();
            bufferedWriter.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
